Valid = {
	validate:function($Area){
		var valid = true;
		var match = {};
		$Area.find('input,select').each(function(){
			var $this = jQuery(this);
			// check required
			if(Validate.getWords($this).indexOf("required") >= 0){
				if(!Valid.required(this.name,$Area)){
					valid = false;
					$this.addClass("validation_failed");
				}else{
					$this.removeClass("validation_failed");
				}
			}
			// check email
			if(Validate.getWords($this).indexOf("email") >= 0){
				if(!Valid.email(this.name,$Area)){
					valid = false;
					$this.addClass("validation_failed");
				}else{
					$this.removeClass("validation_failed");
				}
			}
			// get matches into struct for later
			if(Validate.getWords($this).indexOf("match") >= 0){
				var number = Validate.getWordNumber(Validate.getWords($this),"match");
				match["match"+number] = "";
			}
		});
		// check matches
		for(var key in match){
			var iterator = 0;
			var value = "";
			var value2 = "";
			var matchValid = true;
			var $matches = $Area.find('input[validate*='+key+']');
			$matches.each(function(){
				iterator++;
				var $this = jQuery(this);
				if(iterator == 1){
					value = $this.val() || "";
				} else {
					value2 = $this.val() || "";
					if(value != value2){
						matchValid = false;
					}
				}
			});
			if(!matchValid){
				valid = false;
				$matches.addClass("validation_failed");
			}
			
		}
		return valid;
	},
	getValue:function(name,$Area){
		var value = $Area.find('input[name='+name+'],select[name='+name+']').val() || "";
		return value;
	},
	required:function(name,$Area){
		var value = Valid.getValue(name,$Area);
		return (value.length > 0);
	},
	email:function(name,$Area){
		var value = Valid.getValue(name,$Area);
		var valid = true;
		// there's 1 single @
		if(valid && value.split("@").length != 2){valid = false;}
		// there at least one .
		if(valid && value.indexOf('.') == -1){valid = false;}
		// there's a domain extension.
		var splits = value.split('.');
		if(valid && splits.length > 1 && splits[splits.length-1].length == 0){
			valid = false;
		}
		return valid;
	},
	match:function(name1,name2){
		var value1 = Valid.getValue(name1);
		var value2 = Valid.getValue(name2);
		return (value1 == value2);
	}
};